<?php
    $redis = new Redis();
    $redis->connect('172.23.86.12', 6379);
    $redis->auth("jiruanos@qq.com");


    $url =  'https://mcs.czb365.com/services/v3/gas/queryGasInfoListOilNoNew?';
    $params['channelId'] = 92657226;
    $params['app_key'] = 'appm_api_h592657226';
    $params['app_secret'] = '7152fe62f03845c715ea878a8f67ceb6';
    list($msec, $sec) = explode(' ', microtime());
    $params['timestamp'] = (float)sprintf('%.0f', (floatval($msec) + floatval($sec)) * 1000);

    ksort($params);
    $str = '';
    foreach ($params as $key=>$val){
        $str .= $key.$val;
    }
    $sign = md5($params['app_secret'].$str.$params['app_secret']);

    $params['sign'] = $sign;

    $ch = curl_init();
        curl_setopt($ch,CURLOPT_URL,$url);
        curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
        curl_setopt($ch, CURLOPT_TIMEOUT,10);
        curl_setopt($ch,CURLOPT_POST,1);
        curl_setopt($ch,CURLOPT_POSTFIELDS,$params);
        $res = curl_exec($ch);
//        var_dump($res);exit;
        curl_close($ch);
        $result=json_decode($res,true);

    if($result['code'] == 200) {

        foreach ($result['result'] as $val) {
            if(isset($val['gasId']) && isset($val['gasAddressLongitude']) && isset($val['gasAddressLatitude'])){
                // $redis_key = "oil_card_list_gasId_" . $val['gasId'];
                // $redis->set($redis_key,json_encode($val));
                // $redis->expire($redis_key,60*60*13);
                $redis_key = $val['gasId'];
                $redis->hset('youzhan_area',$redis_key,json_encode($val));

                $redis->rawCommand('geoadd', 'youzhan', $val['gasAddressLongitude'],$val['gasAddressLatitude'],$val['gasId']);
            }
        }

    }


